package com.tma.umedia;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import com.tma.umedia.R.drawable;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FolderAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    
    public FolderAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_item, null);

        TextView item = (TextView)vi.findViewById(R.id.item); // item
        ImageView thumb = (ImageView)vi.findViewById(R.id.image); // thumb image
                
        // Setting all values in listview
        String name = data.get(position).get("name");
        String path = data.get(position).get("path");
        item.setText(name);
        if(name.equals("...")){
        	thumb.setImageDrawable(vi.getResources().getDrawable(R.drawable.back));
        } else {
	        File f = new File(path);
	        if(f.isDirectory()){
	        	thumb.setImageDrawable(vi.getResources().getDrawable(R.drawable.folder));
	        } else { 
	        	thumb.setImageDrawable(vi.getResources().getDrawable(R.drawable.file));
	        }
        }
        return vi;
    }
}
